package cn.cheln.support.v4.pagerui;

import android.app.Activity;
import android.app.LocalActivityManager;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.Parcelable;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import cn.cheln.support.log.Logs;
import cn.cheln.support.v4.view.PagerAdapter;
import cn.cheln.support.v4.view.PagerView;
import java.util.ArrayList;
import java.util.List;

public class ViewPagerHelper extends PagerHelper
  implements ActivityResultBridge
{
  private int currentScreen;
  private ArrayList<PendingContentLoader> mContentLoaders;
  private LoadPendingContentHandler mLoadContentHandler;
  private MPagerAdapter mPagerAdapter;
  private ActivityResultBridge.ActivityResultReceiver mResultReceiver;
  public PagerView mViewPager;
  private int pagernums;
  private List<PageInfo> viewClasses;

  public ViewPagerHelper(Activity paramActivity, Bundle paramBundle)
  {
    super(paramActivity, paramBundle);
  }

  public static View activityToView(Intent paramIntent, ViewPagerHelper paramViewPagerHelper, int paramInt)
  {
    Activity localActivity;
    Window localWindow = paramViewPagerHelper.mLocalActivityManager.startActivity(String.valueOf(paramIntent.getFlags()), paramIntent);
    if (localWindow != null);
    for (View localView = localWindow.getDecorView(); ; localView = null)
    {
      if (localView != null)
      {
        localView.setVisibility(0);
        localView.setFocusableInTouchMode(true);
        ((ViewGroup)localView).setDescendantFocusability(262144);
        int i = paramIntent.getFlags();
        localActivity = getItemActivity(i, paramViewPagerHelper.mLocalActivityManager);
        if (localActivity != null)
        {
          if (localActivity instanceof ActivityResultBridge.ActivityResultReceiver)
            ((ActivityResultBridge.ActivityResultReceiver)localActivity).registerActivityResultBridge(paramViewPagerHelper);
          if (localActivity instanceof PendingContentLoader)
          {
            if (paramViewPagerHelper.mContentLoaders == null)
              paramViewPagerHelper.mContentLoaders = new ArrayList();
            if (i != paramInt)
              break;
            paramViewPagerHelper.mContentLoaders.add(0, (PendingContentLoader)localActivity);
          }
        }
      }
      return localView;
    }
    paramViewPagerHelper.mContentLoaders.add((PendingContentLoader)localActivity);
    return localView;
  }

  private void addPageInfo(int paramInt, PageInfo paramPageInfo)
  {
    Intent localIntent = new Intent(this.yourHomeActivity, paramPageInfo.mCls);
    if (paramPageInfo.mIntent != null)
    {
      localIntent.setAction(paramPageInfo.mIntent.getAction());
      localIntent.putExtras(paramPageInfo.mIntent);
      localIntent.setData(paramPageInfo.mIntent.getData());
    }
    localIntent.setFlags(paramInt);
    View localView = activityToView(localIntent, this, this.currentScreen);
    localView.setId(1);
    this.mPagerAdapter.addPage(paramPageInfo.mCls, null, "", localView);
  }

  private void contentLoad(int paramInt)
  {
    if (this.mContentLoaders == null)
      return;
    this.mLoadContentHandler = new LoadPendingContentHandler(null);
    Message localMessage = this.mLoadContentHandler.obtainMessage();
    localMessage.arg1 = paramInt;
    this.mLoadContentHandler.sendMessageDelayed(localMessage, 100L);
  }

  public static PageInfo genPageInfo(Class<? extends Activity> paramClass, Context paramContext, Class paramClass1)
  {
    return new PageInfo(paramContext, null, null, null, null, paramClass, paramClass1.getName());
  }

  public static Activity getItemActivity(int paramInt, LocalActivityManager paramLocalActivityManager)
  {
    return paramLocalActivityManager.getActivity(String.valueOf(paramInt));
  }

  public void extend(PageInfo paramPageInfo, int paramInt)
  {
    addPageInfo(paramInt, paramPageInfo);
    contentLoad(paramInt);
    this.mPagerAdapter.notifyDataSetChanged();
  }

  public int getCurrentPage(int paramInt)
  {
    return getViewPager().getCurrentItem();
  }

  public int getCurrentScreen()
  {
    return this.currentScreen;
  }

  public PagerView getViewPager()
  {
    if (this.mViewPager == null)
      this.mViewPager = ((PagerView)this.yourHomeActivity.findViewById(2131230843));
    return this.mViewPager;
  }

  public ArrayList<PendingContentLoader> getmContentLoaders()
  {
    return this.mContentLoaders;
  }

  protected void onActivityResult(int paramInt1, int paramInt2, Intent paramIntent)
  {
    if (this.mResultReceiver != null);
    for (int i = 0; ; ++i)
    {
      if (i >= this.viewClasses.size())
      {
        this.mResultReceiver = null;
        return;
      }
      Activity localActivity = getItemActivity(i, this.mLocalActivityManager);
      if ((localActivity == null) || (!(localActivity instanceof ActivityResultBridge.ActivityResultReceiver)))
        continue;
      ((ActivityResultBridge.ActivityResultReceiver)localActivity).handleActivityResult(this.mResultReceiver, paramInt1, paramInt2, paramIntent);
    }
  }

  public void onConfigurationChanged(Configuration paramConfiguration)
  {
  }

  public void onDestroy()
  {
    this.mLocalActivityManager.dispatchDestroy(this.yourHomeActivity.isFinishing());
    this.mPagerAdapter.mPages.clear();
  }

  public void onPause()
  {
    this.mLocalActivityManager.dispatchPause(this.yourHomeActivity.isFinishing());
  }

  public void onResume()
  {
    this.mLocalActivityManager.dispatchResume();
  }

  public void setDisplayScreen(int paramInt)
  {
    this.currentScreen = paramInt;
    if (this.mViewPager == null)
      return;
    this.mViewPager.setCurrentItem(paramInt);
  }

  protected void setupContent(List<PageInfo> paramList)
  {
    this.mPagerAdapter = new MPagerAdapter(this.yourHomeActivity, getViewPager());
    this.pagernums = paramList.size();
    for (int i = 0; ; ++i)
    {
      if (i >= this.pagernums)
      {
        Logs.i("--- -111 ");
        getViewPager().setAdapter(this.mPagerAdapter);
        Logs.i("--- -222 ");
        contentLoad(-1);
        return;
      }
      addPageInfo(i, (PageInfo)paramList.get(i));
    }
  }

  public void startActivityForResult(ActivityResultBridge.ActivityResultReceiver paramActivityResultReceiver, Intent paramIntent, int paramInt)
  {
    this.mResultReceiver = paramActivityResultReceiver;
    this.yourHomeActivity.startActivityForResult(paramIntent, paramInt);
  }

  private class LoadPendingContentHandler extends Handler
  {
    public void handleMessage(Message paramMessage)
    {
      int j;
      int i = paramMessage.arg1;
      if (ViewPagerHelper.this.mContentLoaders != null)
      {
        j = ViewPagerHelper.this.mContentLoaders.size();
        if (j > 0)
          if (i != -1)
            break label94;
      }
      for (int k = 0; ; k = i)
      {
        ((PendingContentLoader)ViewPagerHelper.this.mContentLoaders.get(k)).loadContent();
        ViewPagerHelper.this.mContentLoaders.remove(k);
        if ((i == -1) && (j > 1))
          sendMessageDelayed(obtainMessage(), 500L);
        label94: return;
      }
    }
  }

  protected class MPagerAdapter extends PagerAdapter
  {
    private ViewPagerHelper.PageCacheInfo info;
    private final Context mContext;
    private final PagerView mPager;
    private final ArrayList<ViewPagerHelper.PageCacheInfo> mPages = new ArrayList();

    public MPagerAdapter(Context paramContext, PagerView paramPagerView)
    {
      this.mPager = paramPagerView;
      this.mContext = paramContext;
    }

    public void addPage(Class<?> paramClass, Bundle paramBundle, int paramInt, View paramView)
    {
      addPage(paramClass, null, this.mContext.getResources().getString(paramInt), paramView);
    }

    public void addPage(Class<?> paramClass, Bundle paramBundle, String paramString, View paramView)
    {
      this.info = new ViewPagerHelper.PageCacheInfo(paramClass, paramString, paramView);
      this.mPages.add(this.info);
      notifyDataSetChanged();
    }

    public void addPage(Class<?> paramClass, String paramString, View paramView)
    {
      addPage(paramClass, null, paramString, paramView);
    }

    public void destroyItem(View paramView, int paramInt, Object paramObject)
    {
      ((PagerView)paramView).removeView(ViewPagerHelper.PageCacheInfo.access$1((ViewPagerHelper.PageCacheInfo)this.mPages.get(paramInt)));
    }

    public void finishUpdate(View paramView)
    {
    }

    public int getCount()
    {
      return this.mPages.size();
    }

    public String getTitle(int paramInt)
    {
      return ViewPagerHelper.PageCacheInfo.access$0((ViewPagerHelper.PageCacheInfo)this.mPages.get(paramInt));
    }

    public Object instantiateItem(View paramView, int paramInt)
    {
      View localView1 = ViewPagerHelper.PageCacheInfo.access$1((ViewPagerHelper.PageCacheInfo)this.mPages.get(paramInt));
      View localView2 = null;
      if (localView1 != null)
      {
        int i = ((PagerView)paramView).getChildCount();
        localView2 = null;
        if (i >= paramInt)
        {
          localView2 = ViewPagerHelper.PageCacheInfo.access$1((ViewPagerHelper.PageCacheInfo)this.mPages.get(paramInt));
          ((PagerView)paramView).addView(ViewPagerHelper.PageCacheInfo.access$1((ViewPagerHelper.PageCacheInfo)this.mPages.get(paramInt)), paramInt);
        }
      }
      return localView2;
    }

    public boolean isViewFromObject(View paramView, Object paramObject)
    {
      return (paramView == paramObject);
    }

    public void restoreState(Parcelable paramParcelable, ClassLoader paramClassLoader)
    {
    }

    public Parcelable saveState()
    {
      return null;
    }

    public void startUpdate(View paramView)
    {
    }
  }

  static final class PageCacheInfo
  {
    private final String args;
    private final Class<?> clss;
    private final View mView;

    PageCacheInfo(Class<?> paramClass, String paramString, View paramView)
    {
      this.clss = paramClass;
      this.args = paramString;
      this.mView = paramView;
    }
  }
}

/* Location:           H:\360云盘\lewa_explorer_3.0\bin\FileApp_orig_dex2jar.jar
 * Qualified Name:     cn.cheln.support.v4.pagerui.ViewPagerHelper
 * JD-Core Version:    0.5.2
 */